package com.txts.road.admin.deviceSys.controller;

import com.txts.base.common.domain.PageResult;
import com.txts.base.common.domain.ResponseDTO;
import com.txts.road.admin.common.annotation.Anonymous;
import com.txts.road.admin.common.annotation.Log;
import com.txts.road.admin.common.core.controller.BaseController;
import com.txts.road.admin.common.core.domain.AjaxResult;
import com.txts.road.admin.common.core.page.TableDataInfo;
import com.txts.road.admin.common.enums.BusinessType;
import com.txts.road.admin.common.utils.poi.ExcelUtil;
import com.txts.road.admin.deviceSys.domain.VehicleDevice;
import com.txts.road.admin.deviceSys.service.IVehicleDeviceService;
import com.txts.road.admin.raceSys.domain.RaceSys;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车载设备信息Controller
 *
 * @author ruoyi
 * @date 2025-05-15
 */
@RestController
@RequestMapping("/DeviceSys/deviceInfo")
@Tag(name = "车载设备接口")
public class VehicleDeviceController extends BaseController {
    @Resource
    private IVehicleDeviceService vehicleDeviceService;

    /**
     * 查询车载设备信息列表
     */
    @Anonymous
    @GetMapping("/list")
    @Operation(summary = "查询车载设备信息列表", description = "根据条件查询车载设备信息列表")
    public ResponseDTO<PageResult<VehicleDevice>> list(VehicleDevice vehicleDevice) {
        startPage();
        List<VehicleDevice> list = vehicleDeviceService.selectVehicleDeviceList(vehicleDevice);
        return getDataTable(list);
    }

    /**
     * 导出车载设备信息列表
     */
    @PreAuthorize("@ss.hasPermi('DeviceSys:deviceInfo:export')")
    @Log(title = "车载设备信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出车载设备信息列表", description = "导出车载设备信息列表")
    public void export(HttpServletResponse response, VehicleDevice vehicleDevice) {
        List<VehicleDevice> list = vehicleDeviceService.selectVehicleDeviceList(vehicleDevice);
        ExcelUtil<VehicleDevice> util = new ExcelUtil<VehicleDevice>(VehicleDevice.class);
        util.exportExcel(response, list, "车载设备信息数据");
    }

    /**
     * 获取车载设备信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('DeviceSys:deviceInfo:query')")
    @GetMapping(value = "/{deviceName}")
    @Operation(summary = "获取车载设备信息详细信息", description = "根据设备名称获取车载设备信息详细信息")
     public ResponseDTO<Object> getInfo(@PathVariable("deviceName") String deviceName) {
        return success(vehicleDeviceService.selectVehicleDeviceByDeviceName(deviceName));
    }

    /**
     * 新增车载设备信息
     */
    @PreAuthorize("@ss.hasPermi('DeviceSys:deviceInfo:add')")
    @Log(title = "车载设备信息", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增车载设备信息", description = "新增车载设备信息")
    public ResponseDTO<Object>add(@RequestBody VehicleDevice vehicleDevice) {
        return toAjax(vehicleDeviceService.insertVehicleDevice(vehicleDevice));
    }

    /**
     * 修改车载设备信息
     */
    @PreAuthorize("@ss.hasPermi('DeviceSys:deviceInfo:edit')")
    @Log(title = "车载设备信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改车载设备信息", description = "修改车载设备信息")
    public ResponseDTO<Object>edit(@RequestBody VehicleDevice vehicleDevice) {
        return toAjax(vehicleDeviceService.updateVehicleDevice(vehicleDevice));
    }

    /**
     * 删除车载设备信息
     */
    @PreAuthorize("@ss.hasPermi('DeviceSys:deviceInfo:remove')")
    @Log(title = "车载设备信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deviceNames}")
    @Operation(summary = "删除车载设备信息", description = "删除车载设备信息")
    public ResponseDTO<Object>remove(@PathVariable String[] deviceNames) {
        return toAjax(vehicleDeviceService.deleteVehicleDeviceByDeviceNames(deviceNames));
    }


    @GetMapping("/listAllshebei")
    @Operation(summary = "查询所有设备", description = "查询所有设备列表")
    public  ResponseDTO<Object>  listAllshebei() {
        return AjaxResult.success(vehicleDeviceService.selectAllshebei());
    }
}
